import React, { useEffect, useState } from 'react';
import { Form, Input, Select, Button, notification } from 'antd';
import { DatePicker, Space } from 'antd';
import '../../../scss/lhq/supplieredit.scss'
import { useNavigate, useLocation } from 'react-router-dom'
import { requirent_edit } from '../../../tools/lhq/api'

function Supplieredit(props) {
    const [date,setDate] = useState()
    const [from] = Form.useForm();
    // 接收state参数
    var location = useLocation()
    useEffect(() => {
        console.log(location.state)
        from.setFieldsValue({
            id: location.state.id,
            date: location.state.date,
            number: location.state.number,
            status: location.state.status,
            launch: location.state.launch,
            response: location.state.response,
            process: location.state.process,
            note: location.state.note,
        })
    }, [])
    // 日期
    const onChange = (date, dateString) => {
        setDate(dateString)
    };

    var navigate = useNavigate()
    const onFinish = (values) => {
        setDate(date) 
        requirent_edit({ id: location.state.id, date: date, number: values.number, status: values.status, 
            launch: values.launch, response: values.response, process:values.process,note:values.note }).then((res) => {
            console.log("编辑请求",res.data)
            notification.success({ message: '编辑成功!' });
            navigate('/index/requirent')
        })
    };

    // 保存编辑
    return (
        <div className='supplieredit'>
            <Form form={from} className='form' initialValues={{ remember: true }} onFinish={onFinish}
                labelCol={{ span: 6 }} wrapperCol={{ span: 18 }}>
                <Form.Item className='item' label="发起日期" name="date">
                    <Space direction="vertical">
                        <DatePicker onChange={onChange} />
                    </Space>
                </Form.Item>
                <Form.Item className='item' label="请购单编号" name="number">
                    <Input placeholder='请输入请购单编号' />
                </Form.Item>
                <Form.Item className='item' label="采购单状态" name="status">
                    <Select
                        placeholder="所有"
                        style={{ width: 120 }}
                        options={[
                            { value: '待分配' },
                            { value: '已分配' },
                            { value: '已完成' }
                        ]}
                    />
                </Form.Item>
                <Form.Item className='item' label="请购发起人" name="launch">
                    <Input placeholder='请输入请购发起人' />
                </Form.Item>
                <Form.Item className='item' label="请购负责人" name="response">
                    <Input placeholder='请输入请购负责人' />
                </Form.Item>
                <Form.Item className='item' label="请购审核人" name="process">
                    <Input placeholder='请输入请购审核人' />
                </Form.Item>
                <Form.Item className='item' label="请购单备注" name="note">
                    <Input placeholder='请输入请购单备注' />
                </Form.Item>
                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                    <Button type="primary" htmlType="submit" >保存</Button>
                </Form.Item>
            </Form>
        </div>
    );
}

export default Supplieredit;